<template>
  <div class="flex h-32 w-full flex-row">
    <div class="mt-2 grid w-full grid-cols-6 gap-2">
      <template v-for="item in top_plate_info" :key="item.plate_id">
        <div class="flex flex-col justify-around rounded bg-red-500 text-white">
          <div class="flex cursor-pointer justify-between p-2 text-lg leading-8" @click="Utils.forwordBk(item.plate_id)">
            <span class="truncate">{{ item.plate_name }}</span>
            <span class="font-semibold">{{ (item.core_avg_pcp * 100).toFixed(2) }}%</span>
          </div>
          <div class="flex justify-between px-1.5 text-right text-sm">
            <div
              @click="Utils.forwordGu(item.led_rising_stocks.items[0].symbol)"
              class="cursor-pointer leading-6"
              v-if="item.led_rising_stocks.items.length > 0"
            >
              <div>{{ item.led_rising_stocks.items[0].stock_chi_name }}</div>
              <div class="font-semibold">+{{ (item.led_rising_stocks.items[0].change_percent * 100).toFixed(2) }}%</div>
            </div>
            <div
              @click="Utils.forwordGu(item.led_rising_stocks.items[1].symbol)"
              class="cursor-pointer leading-6"
              v-if="item.led_rising_stocks.items.length > 1"
            >
              <div>{{ item.led_rising_stocks.items[1].stock_chi_name }}</div>
              <div class="font-semibold">+{{ (item.led_rising_stocks.items[1].change_percent * 100).toFixed(2) }}%</div>
            </div>
          </div>
        </div>
      </template>
      <template v-for="item in bottom_plate_info" :key="item.plate_id">
        <div class="flex flex-col justify-around rounded bg-green-600 text-white">
          <div class="flex cursor-pointer justify-between p-2 text-lg leading-8" @click="Utils.forwordBk(item.plate_id)">
            <span class="truncate">{{ item.plate_name }}</span>
            <span class="font-semibold">{{ (item.core_avg_pcp * 100).toFixed(2) }}%</span>
          </div>
          <div class="flex justify-between px-1.5 text-right text-sm">
            <div
              @click="Utils.forwordGu(item.led_falling_stocks.items[0].symbol)"
              class="cursor-pointer leading-6"
              v-if="item.led_falling_stocks.items.length > 0"
            >
              <div>{{ item.led_falling_stocks.items[0].stock_chi_name }}</div>
              <div class="font-semibold">{{ (item.led_falling_stocks.items[0].change_percent * 100).toFixed(2) }}%</div>
            </div>
            <div
              @click="Utils.forwordGu(item.led_falling_stocks.items[1].symbol)"
              class="cursor-pointer leading-6"
              v-if="item.led_falling_stocks.items.length > 1"
            >
              <div>{{ item.led_falling_stocks.items[1].stock_chi_name }}</div>
              <div class="font-semibold">{{ (item.led_falling_stocks.items[1].change_percent * 100).toFixed(2) }}%</div>
            </div>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>
<script setup>
import axios from 'axios';
import Utils from '../utils/index';
import { ref } from 'vue';

const top_plate_info = ref([]);
const bottom_plate_info = ref([]);
function fetchData() {
  axios.get('https://flash-api.xuangubao.cn/api/stage2/plate/top_info?count=20&fields=all').then(function (res) {
    let result = res.data.data;
    let top_plates = result.top_plate_info.map((e) => e.plate_id + '');
    window.localStorage.setItem('top_plates', JSON.stringify(top_plates));
    top_plate_info.value = result.top_plate_info.slice(0, 3);
    bottom_plate_info.value = result.bottom_plate_info.slice(0, 3);
  });
}
defineExpose({
  fetchData,
});
</script>
